#!/usr/bin/python
#-*-coding: utf-8 -*-

__all__ = [u'GuiPart']

########## DO NOT CHANGE THESE LINES ###########################################
import sys
from pylot.core import (ENCODING, Path)
try : __file__
except NameError : co = sys._getframe(0).f_code ; __file__ = co.co_filename
ufile = __file__.decode(ENCODING)
if ufile.strip() : PLUGIN_PATH = Path(ufile).abspath().parent
else : PLUGIN_PATH = Path(u'.').abspath()
########## DO NOT CHANGE THESE LINES ###########################################

from PyQt4 import QtGui
from PyQt4.QtCore import SIGNAL

from handler import HandlerPart
from pylot.qtgui import (load_designer_file, GuiAutoWidget)

_GuiPart, WidgetClass = load_designer_file(u'designer.ui', [PLUGIN_PATH])
class GuiPart(WidgetClass, GuiAutoWidget, _GuiPart):
  u"""
  A very simple divider
  """
  def __init__(self, handler=None):
    if handler is None :
      handler = HandlerPart()
      handler.init()
    GuiAutoWidget.__init__(self, handler)
    self._plugin_path = PLUGIN_PATH

    WidgetClass.__init__(self)
    self.setupUi(self) # Designer file initialization

    self.i18n = self.addPlugin(u'tools_i18n', self.handler.i18n,
      plugin_id=u'i18n', auto_fill_widget=False)
    self.testing = self.addPlugin(u'tools_testing', self.handler.testing,
      auto_fill_widget=False)

    self.autoCreateToolBars(self.i18n)
    self.autoCreateToolBars(self.testing)

    self.main_layout.addWidget(self.i18n)

    # Widget creation
    self._createPreferences()
    self._createActions()
    self._createConnexions()
    self._createMenu()
    self._createToolBars()

    # Force emitting signal to be sure that testing values are up-to-date
    self.i18n.widget_path.emitDataChangedSignal()

  # ============================================================================
  # Widget Creation
  # ============================================================================

  def _createPreferences(self):
    self.pref = self.testing.pref

  def _createActions(self):
    u"""
    See 'designer.ui' file (Qt Designer file) and sub-plugins.
    """
    pass

  def _createConnexions(self):
    self.connect(self.action_check_plugin, SIGNAL('triggered()'),
                 self.handler.actionCheckPlugin)
    self.connect(self.action_test_plugin, SIGNAL('triggered()'),
                 self.handler.actionTestPlugin)

    self.connect(self.i18n.widget_path, SIGNAL('dataChanged'),
                 self.testing.widget_path.setValue)

  def _createMenu(self):
    self.menu_file = self.addMenu_(self.i18n.menu_file)
    self.menu_translate = self.addMenu_(self.i18n.menu_translate)
    self.menu_testing = self.addMenu_(self.testing.menu_testing)

  def _createToolBars(self):
    pass

  # ============================================================================
  # Widget dynamic changes
  # ============================================================================

  def _fillMenus(self, level):
    self._fill(self.testing.menu_testing, [
      self.action_check_plugin,
      self.action_test_plugin
      ])

  def _fillToolBars(self, level):
    self._fill(self.testing.tool_bar_testing, [
      self.action_check_plugin,
      self.action_test_plugin
      ])

  def _decorate (self):
    self._setIcons([
      (self.action_test_plugin, u'test_plugin.png'),
      (self.action_check_plugin, u'check_plugin.png')
      ])

  def _translate(self):
    pass

  # ============================================================================
  # Widget/HandlerPart Connections
  # ============================================================================

  # ============================================================================
  # Widget Public Methods
  # ============================================================================

if __name__ == u"__main__":
  from PyQt4.QtGui import QApplication
  app = QApplication([])
  gui = GuiPart()
  gui.show()
  ret = app.exec_()
